package com.kjlink.internal.workreport.base.enums;

import java.time.LocalDate;
import java.util.Arrays;

/**
 * 描述:
 * 可输入的日期
 *
 * @author Vic.xu
 * @since 2024-05-06 11:16
 */
public enum InputtableDateEnum {

    TODAY("今天", 0),
    YESTERDAY("昨天", -1),
    ;
    private String name;
    private Integer value;

    InputtableDateEnum(String name, Integer value) {
        this.name = name;
        this.value = value;
    }


    public String getName() {
        return name;
    }

    public Integer getValue() {
        return value;
    }

    public LocalDate getDate() {
        return LocalDate.now().plusDays(value);
    }

    public static boolean isLegalDate(LocalDate date) {
        return Arrays.stream(InputtableDateEnum.values()).anyMatch(inputtableDateEnum -> inputtableDateEnum.getDate().isEqual(date));
    }

    public static InputtableDateEnum getByDate(LocalDate date) {
        return Arrays.stream(InputtableDateEnum.values()).filter(inputtableDateEnum -> inputtableDateEnum.getDate().isEqual(date)).findFirst().orElse(TODAY);
    }

    public static void main(String[] args) {
        System.out.println(InputtableDateEnum.isLegalDate(LocalDate.now().plusDays(1)));
    }

}
